const log = require('../util/log')

module.exports = (req, res) => {
  const mongoMng = require('../mng/mongoMng')
  if (!mongoMng.db) {
    log('未连接mongo')
    resolve({
      result: -1,
      msg: '系统错误'
    })
    return;
  }
  require('../util/service').handlePost(req, res, (reqObj, resolve) => {
    mongoMng.db.collection('user').find({
      phone: req.session.customer.phone
    }).toArray((err, result) => {
      if (err) {
        log(err);
        resolve({
          result: -1,
          msg: '系统错误'
        })
        return;
      }
      if (result.length == 0) {
        resolve({
          alipay: ''
        })
      } else {
        resolve({
          alipay: result[0].alipay || ''
        })
      }
    });
  })
}
